<?php
require_once('./Controller.php');
require_once('../models/User.php');
class LoginController extends Controller{

    public function user($username)
    {
        $model = new User();

        //找出user的数据,有就跳转,没有就创建并跳转
        $is = $model->find($username);
        if($is){
            $url = '../controllers/IndexController.php';
            header("Location: ".$url);
            exit;
        }
    }

}

$login = new LoginController();

//退出登陆
if(isset($_GET['layout']) && $_GET['layout'] == 1){
    //退出登陆
    session_destroy();
    $url = '../views/login.html';

    $login->redirect($url);
}

//登陆
if(isset($_POST['username']) && isset($_POST['userid'])){
    //跳转到index控制器展示

    $url = '../controllers/IndexController.php';

    $login->redirect($url);
    exit();

}else{
    if(isset($_POST['username']) && !empty($_POST['username'])){
        $login->user($_POST['username']);
        exit;
    }
    $url = '../views/login.html';

    $login->redirect($url);
    exit();
}


